package com.struc.td;
import java.util.HashMap;

import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL10;

public class Main implements ApplicationListener{
	public static int WIDTH;
	public static int HEIGHT;
	public static Sounds soundMachine;
	public boolean gameOn;
	State activeState;
	HashMap<Integer, State> stateList = new HashMap<Integer,State>();
	private UnitTester unitTester;
	private GuiTester guiTester;
	//runs when the application starts. Will initiate sound, textures and states.
	public void create() {
		new Sounds();
		new StaticTextures();
		stateList.put(1,new MainMenu(this));
		stateList.put(2,new Game(this));
		stateList.put(3,new Highscore(this));
		stateList.put(4,new Pause(this));
		stateList.put(5, new Lost(this));
		stateList.put(6, new TalentTree(this));
		stateList.get(1).enter();
		activeState = stateList.get(1);
		
		// Remove these comments, and the one in render(), to run tests.
		//unitTester = new UnitTester(this);
		//unitTester.run();
		//guiTester = new GuiTester(this);
	}
	
	//method that returns an state
	public State getState(int id) {
		return stateList.get(id);
	}
	
	//method to set an active state
	public void setState(int id) {
		activeState.leave();
		stateList.get(id).enter();
		activeState = stateList.get(id);
	}
	public void setGameOn(boolean b){
		gameOn = b;
	}
	
	public boolean getGameOn(){
		return gameOn;
	}
	
	@Override
	public void dispose() {
	}
	public void pause() {
	}

	//this render will update and render our active state
	public void render() {
		GL10 gl = Gdx.graphics.getGL10();
		gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
		activeState.update();
		activeState.render(); 
		//guiTester.runNextTest();
	}


	public void resize(int width, int height) {
		WIDTH = width;
		HEIGHT = height;
		((Game) stateList.get(2)).resized();
	}

	public void resume() {

	}
}